'use strict';

const crypto = require('crypto');
const jsonWebToken = require('./kujomiva/jsonWebToken');
const smsVerifyCode = require('./kujomiva/smsVerifyCode');

module.exports = {
    ...jsonWebToken,
    ...smsVerifyCode,
    md5(param) {
        return crypto.createHash('md5').update(param).digest('hex');
    },
    // 生成n位数字的方法
    createNum(numLength = 6) {
        let num = '';
        for (let i = 0; i < numLength; i++) {
            num += Math.floor(Math.random() * 10);
        }
        return num;
    },
    // 转为promise函数
    async promisify(fn, receiver) {
        return (...args) => {
            return new Promise((resolve, reject) => {
                fn.apply(receiver, [...args, (err, res) => {
                    return err ? reject(err) : resolve(res);
                }]);
            });
        };
    }
};
